package com.yzy.config.mybatis;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.optimize.JsqlParserCountOptimize;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: mybatis-plus 配置类
 */
@Configuration
public class MybatisPlusConfig {

    /**
     * @Description: 添加插件
     */
//    @Bean
//    public mybatisPlusInterceptor mybatisPlusInterceptor() {
//        mybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
//        // 乐观锁插件
//        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
//        // 分页插件
//        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
//        // 设置请求的页面大于最大页后操作， true调回到首页，false 继续请求  默认false
//        // paginationInterceptor.setOverflow(false);
//        // 设置最大单页限制数量，默认 500 条，-1 不受限制
//        // paginationInterceptor.setLimit(500);
//        return interceptor;
//    }

//    /**
//     * @Description: 自定义id
//     */
//    @Bean
//    public CustomIdGenerator customIdGenerator() {
//        return new CustomIdGenerator();
//    }

    /**
     * @Description: sql拦截处理
     */
//    @Bean
//    public MyMetaObjectHandler myMetaObjectHandler() {
//        return new MyMetaObjectHandler();
//    }

    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
        paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
        return paginationInterceptor;
    }
}
